package com.dhy.dbCore.transaction.util;

import lombok.Data;

/**
 * @author 大忽悠
 * @create 2022/6/6 20:35
 */
@Data
public class DefaultTransactionStatus {
    /**
     * 是否进行事务回滚
     */
    private Boolean rollBackOnly;
    /**
     * 是否为新事务
     */
    private Boolean isNewTransaction;
    /**
     * 当前事务是否已经结束了
     */
    private Boolean isCompleted;

    public DefaultTransactionStatus(Boolean rollBackOnly, Boolean isNewTransaction, Boolean isCompleted) {
        this.rollBackOnly = rollBackOnly;
        this.isNewTransaction = isNewTransaction;
        this.isCompleted = isCompleted;
    }

    /**
     * 默认只对unchecked ex进行回滚
     */
    public Boolean rollBackOn(Throwable ex){
        return (ex instanceof RuntimeException || ex instanceof Error);
    }
}
